/** vite配置文件
 * @ 版  权:   hchhIOT
 * @ 作  者: 黄传鸿 <hchhyzc@foxmail.com>
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import config from './package.json';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir)
}
// https://vitejs.dev/config/
export default defineConfig({
  /*——————————————————————————————————————————————|服务器配置*/
  server: {
    host: config.home_addr,/*ip地址*/
    port: config.home_port,/*端口*/
    cors: false,
    open: true,/*是否打开浏览器*/
    /*--------------------------------------------|代理(跨域)*/
    proxy: {
      "/api": {
        target: config.data_addr,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  /*——————————————————————————————————————————————|静态资源文件夹*/
  publicDir: "public",
  /*——————————————————————————————————————————————|别名配置*/
  resolve: {
    /*别名*/
    alias: [{
      find: '@',
      replacement: pathResolve('src')
    }]
  },
  /*——————————————————————————————————————————————|插件*/
  plugins: [vue(),
  AutoImport({
    imports: [
      'vue',
      {
        'naive-ui': [
          'useDialog',
          'useMessage',
          'useNotification',
          'useLoadingBar'
        ]
      }
    ]
  }),
  Components({
    resolvers: [NaiveUiResolver()]
  })
  ]
})
